package system

import (
	"github.com/go-yaml/yaml"
	"io/ioutil"
	"log"
)

type Configuration struct {
	Driver      string   `yaml:"driver"`  // signup enabled or not
	DbName     string `yaml:"db_name"` // qiniu
	User     string `yaml:"user"`
	Password    string `yaml:"password"`
	Host        string `yaml:"host"`
}

var configuration *Configuration

func LoadConfiguration(path string) {
	data, err := ioutil.ReadFile(path)
	if err != nil {
		log.Fatal("error: %v", err)
	}
	var config Configuration
	err = yaml.Unmarshal(data, &config)
	if err != nil {
		log.Fatalf("error: %v", err)
	}
	configuration = &config
	log.Println("config load succeessfully:%v", configuration)
}

func GetConfiguration() *Configuration {
	if configuration == nil {
		LoadConfiguration("conf/conf.yaml")
	}
	return configuration
}
